package com.guigu.servicegoods.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.guigu.common_util.pojo.IdWorker.IdWorker;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.guigu.servicegoods.mapper")
public class QingChengConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    public IdWorker idWorker() {
        return new IdWorker(1,1);
    }

    /**
     * 上架广播模式
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchangesj() {
        return new FanoutExchange("exchange.sj");
    }

    /**
     * 下架广播模式
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchangexj() {
        return new FanoutExchange("exchange.xj");
    }

    /**
     * 上架添加详细页
     * @return
     */
    @Bean
    public Queue queue_sjxx(){
        return new Queue("queue.sjxx");
    }

    /**
     * 上架添加索引库
     * @return
     */
    @Bean
    public Queue queue_sjsy(){
        return new Queue("queue.sjsy");
    }

    /**
     * 下架添加详细页
     * @return
     */
    @Bean
    public Queue queue_xjxx(){
        return new Queue("queue.xjxx");
    }

    /**
     * 下架添加索引库
     * @return
     */
    @Bean
    public Queue queue_xjsy(){
        return new Queue("queue.xjsy");
    }

    //上架交换机绑定
    @Bean
    public Binding binding1(@Qualifier("queue_sjxx")Queue a, FanoutExchange fanoutExchangesj){
        return BindingBuilder.bind(a).to(fanoutExchangesj);
    }

    @Bean
    public Binding binding2(@Qualifier("queue_sjsy")Queue b, FanoutExchange fanoutExchangesj){
        return BindingBuilder.bind(b).to(fanoutExchangesj);
    }

    //下架交换机绑定
    @Bean
    public Binding binding3(@Qualifier("queue_xjxx")Queue c,FanoutExchange fanoutExchangexj){
        return BindingBuilder.bind(c).to(fanoutExchangexj);
    }

    @Bean
    public Binding binding4(@Qualifier("queue_xjsy")Queue d,FanoutExchange fanoutExchangexj){
        return BindingBuilder.bind(d).to(fanoutExchangexj);
    }
}
